<?php

$act=$_GET["act"];
$hang=$_GET["id"];

if($act==""){
	
	$query=mysql_query("select * from product");
    $tongItems=mysql_num_rows($query);	
	if($tongItems%10==0){
	   $tongPage=$tongItems/10;
    }else{
	   $tongPage=(int)($tongItems/10+1);
   }
	
	$pageNow=$_GET['pageNow'];
	
	if($pageNow==""||$pageNow<1){
		$pageNow=1;
	}
	if($pageNow>$tongPage){
		$pageNow=$tongPage;
	}
	
	$start=($pageNow-1)*10;
	$num=10;
	
	
$sql2=mysql_query("select * from category");
include("view/search.php");	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
echo "<p align='center'>";
  
  
if($tongPage>1){
	
if($pageNow==1){
	    echo "|<<&nbsp;<";
	}else{
		echo "<a href='index.php?pageNow=1'> |<< </a> &nbsp;";
		echo "<a href='index.php?pageNow=".($pageNow-1)."'> < </a>";
    }


$i=$pageNow;
if($i<=$tongPage-5){
	while($i<$pageNow+5){
		if($i==$pageNow){
		    echo "&nbsp;&nbsp;<font color='red'><b><a href='index.php?pageNow=".$i."'>".$i."</a></b></font>&nbsp;&nbsp;";
		}else{
			echo "&nbsp;&nbsp;<a href='index.php?pageNow=".$i."'>".$i."</a>&nbsp;&nbsp;";
		}
		$i++;
	}
}else{
	if($tongPage<=5){
		$i=1;
		while($i<=$tongPage){
			if($i==$pageNow){
		    	echo "&nbsp;&nbsp;<font color='red'><b><a href='index.php?pageNow=".$i."'>".$i."</a></b></font>&nbsp;&nbsp;";
			}else{
				echo "&nbsp;&nbsp;<a href='index.php?pageNow=".$i."'>".$i."</a>&nbsp;&nbsp;";
			}
			$i++;
		}
	}else{
		$i=$tongPage-5;
		while($i<=$tongPage){
			if($i==$pageNow){
		    	echo "&nbsp;&nbsp;<font color='red'><b><a href='index.php?pageNow=".$i."'>".$i."</a></b></font>&nbsp;&nbsp;";
			}else{
				echo "&nbsp;&nbsp;<a href='index.php?pageNow=".$i."'>".$i."</a>&nbsp;&nbsp;";
			}
			$i++;
		}
	}
}

	if($pageNow==$tongPage){
		echo ">&nbsp;>>|";
	}else{
		echo "<a href='index.php?pageNow=".($pageNow+1)."'> > </a> &nbsp;";
		echo "<a href='index.php?pageNow=$tongPage'> >>| </a>";	
	} 
}


echo "</p>";
	
	$result=mysql_query("select masp,tensp,giaban,hinhanh from product limit $start,$num ");
	if($result){
		$t=mysql_num_rows($result);
		$i=1;
		while(($row=mysql_fetch_row($result))&&($i<=$t)){
			$i++;	
			$sql1=mysql_query("select* from watchingproduct where masp='$row[0]'");
			$sl=mysql_fetch_array($sql1);

?>				
			
			<div class="item">
				<img src="images/bordtop.gif" alt="" width="274" height="2" />
				<div>
					<img src="images/sanpham/<?php echo $row[3]; ?>" alt="" width="102" height="88" class="items" />
					<h1><?php echo $row[1]; ?></h1>
					<span><?php if($sl['soluongcon']==0){
									echo "Đã hết hàng";
								}else{
									echo "<b size='8'>Hiện còn:    </b>
									<font color=blue size='6'>".$sl['soluongcon']."</font>    <b>&nbsp;&nbsp;chiếc</b>";
								}?> 
                     </span>
					<p><strong><?php echo $row[2]."VNĐ"; ?></strong></p>
					<a href="index.php?page=detailproduct&&id=<?php echo $row[0]; ?>"><img src="images/button1.gif" alt="" width="129" height="20"/></a>
					<a href="index.php?page=cart&&act=buy&&masp=<?php echo $row[0]; ?>"><img src="images/button2.gif" alt="" width="127" height="20" /></a>
				</div>
				<img src="images/bordbot.gif" alt="" width="274" height="2" />
			</div>
            
		<?php if($i%2) {echo "<br/>";}
		}
	}else{
		$sql2=mysql_query("select * from category");
	    include("view/search.php");
		 echo "<center><br>Xin lỗi, không tìm thấy sản phẩm mà bạn cần trong dữ liệu!<br><br>"; 
	}?>


<?php 	
}elseif($act=="detail"){
	
	$masp=$_GET["masp"];
	$sql=mysql_query("select masp,tensp,hinhanh,hinhlon,trongluong,kichthuoc,mausac,mang,manhinh,bonho,ngonngu,dacdiem,tinhnang,tongquan,thoigianhdpin,hdsd from product where masp='$masp'");
 	$row=mysql_fetch_row($sql);
 	$km=mysql_query("select masp,hinhthuckm,tungay,denngay,trangthai from promotion where masp='$masp'");
 	$ht=mysql_fetch_row($km);
	
	include("view/detailproduct.php");
}
?>


